#!/usr/bin/perl

use strict;
use warnings;
use LWP::UserAgent;
use Benchmark;
my $TT0 = new Benchmark;

my $url = "http://www.baidu.com";
my $request_times = 1000;

print "\n Now begin testing ... \n";
my $lwp = new LWP::UserAgent(agent => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; CIBA)');

for(1..$request_times) {
        my $request = HTTP::Request->new(GET=>$url);
        $request->header(Accept=>'text/html');
        my $response = $lwp->request($request);
         if ($response->is_success) {
                 print " $_\tOK!\n";
         }
         else {
                 print " $_\tFaild!\n";
                 redo;
         }
}
my $TT1 = new Benchmark;
my $td = Benchmark::timediff($TT1, $TT0);
$td = Benchmark::timestr($td);
my ($sec) = ($td =~ /(\d+).*/);
my $speed = sprintf("%0.1f",$request_times/$sec);
print "\n Time expend: $td\n Average Speed: $speed Times Per Second\n\n Press Enter to close me ... \7";

<STDIN>;